package com.superhelper.superhelper_web.controller.setting;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.superhelper.superhelper_web.controller.base.AbstractController;
import com.superhelper.superhelper_web.domain.PageModel;
import com.superhelper.superhelper_web.domain.Resp;
import com.superhelper.superhelper_web.domain.Role;


/**
 * 
 *
 */
@Controller
@RequestMapping("admin/role")
public class RoleController extends AbstractController {

	@RequestMapping("addRole")
	public String addRole(ModelMap model) {
		return "admin/role/addRole";
	}

	@RequestMapping("editRole")
	public String editRole(ModelMap model, Integer id) {

		Role role = adminService.getRoleById(id);
		model.put("role", role);
		return "admin/role/editRole";
	}

	/**
	 * 添加角色
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("saveRole")
	public Resp addRole(Role role) {
		boolean result = adminService.addRole(role);
		return result ? success("添加成功!") : fail("网络不稳定,添加失败");
	}

	/**
	 * 编辑角色
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("updateRole")
	public Resp updateRole(Role role) {
		boolean result = adminService.editRole(role);
		return result ? success("修改成功!") : fail("网络不稳定,添加失败");
	}

	/**
	 * 查看
	 * 
	 * @return
	 */
	@RequestMapping("getRole")
	public String getRole(ModelMap model, HttpServletRequest request,
			PageModel pageModel) {
		List<Role> list = adminService.getRole(pageModel);
		model.put("roles", list);
		return "admin/role/getRole";
	}

	/**
	 * 删除
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("delRole")
	public Resp delRole(Integer id) {
		return adminService.delRoleById(id) ? success("删除成功!")
				: fail("网络不稳定,删除失败");
	}

}
